//
//  CMDBSearchWorksParam.swift
//  CMDB
//
//  Created by 王磊 on 17/4/13.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

class CMDBSearchWorksParam: CMDBBasicParamBean {
    
    var condition: String = ""
    
    var releaseYearSort: String = ""
    
    var boxOfficeSort: String = ""
    
    var durationSort: String = ""
    
    var attribute: String = ""
    
    var types: String {
        
        return CMDBSearchWorksTempParam.castStringArrToString(searchWorksTempParam.types)
    }
    
    var areas: String {
        
        return CMDBSearchWorksTempParam.castStringArrToString(searchWorksTempParam.areas)
    }
    var releaseYears: String {
        
        return CMDBSearchWorksTempParam.castStringArrToString(searchWorksTempParam.releaseYears)
    }
    var durations: String {
        
        return CMDBSearchWorksTempParam.castStringArrToString(searchWorksTempParam.durations)
    }
    var episodes: String {
        
        return CMDBSearchWorksTempParam.castStringArrToString(searchWorksTempParam.episodes)
    }
    var boxOffices: String {
        
        return CMDBSearchWorksTempParam.castStringArrToString(searchWorksTempParam.boxOffices)
    }
    
    var searchWorksTempParam: CMDBSearchWorksTempParam = CMDBSearchWorksTempParam()
}
extension CMDBSearchWorksParam {
    
    override func URLString() -> String {
        
        return CMDB_Http_Formal_Domain + "/app/search/\(server_Version)/searchWorks?"
    }
}

class CMDBSearchWorksTempParam: NSObject {
    
    var types: Array<String> = []
    
    var areas: Array<String> = []
    
    var releaseYears: Array<String> = []
    
    var durations: Array<String> = []
    
    var episodes: Array<String> = []
    
    var boxOffices: Array<String> = []
    
}
extension CMDBSearchWorksTempParam {
    
    static func castStringArrToString(arr: Array<String>) -> String {
        
        let mutable = NSMutableArray()
        
        _ = arr.map({
            
            mutable.addObject($0)
            
        })
        
        let jsonData = try? NSJSONSerialization.dataWithJSONObject(mutable, options: .PrettyPrinted)
        
        guard let jsonTemp = jsonData else {
            
            return ""
        }
        let jsonStr = String(data: jsonTemp,encoding: NSUTF8StringEncoding)
        
        return jsonStr!
    }
}

//token	String	34jdskf89348934	token
//condition	String	宝贝计划	搜索条件
//releaseYearSort	int	1	上映时间，0:正序，1：倒序
//boxOfficeSort	int	1	票房，0:正序，1：倒序
//durationSort	int	1	片长，0:正序，1：倒序
//attribute	int	1	属性标签
//types	string	['tid', 'tid']	类型数组
//areas	string	['aid', 'aid']	发行地区
//releaseYears	string	['id', 'id']	上映时间
//durations	string	['id', 'id']	多个片长
//episodes	string	['id', 'id']	多个集数
//boxOffices	string	['id', 'id']	多个票房